
function ProbabilitiesManager:pruneUselessKeys()

	if gField.entityTypes.Key
	then
		gLogger:enterGroup("Prune useless keys")
	
	
		-- remove all keys that are not collasped and that are related to doors that collasped as unlocked and open
	
		for keyName, key in pairs(gField.entityTypes.Key) do
		
			local relatedDoor = gField.entityTypes.Door[keyName]
			
			if
				(
					(not key:isPropertyCollasped("CurrentContainer")) or
					(key.currentContainerCollapseBeat == gField.beat) 			-- we accept keys just collapsed because they are not yet been viewed bt the player
				) and
				not relatedDoor:hasUndeterminedSate() and
				relatedDoor:isEnabled()
			then
				gLogger:log("Remove Key " .. keyName, true)
				gField:removeEntity(key)
			end
		end

		gLogger:leaveGroup()
	end
end